<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
		<title>宝尊河马数据导出</title>
		<link rel="stylesheet" href="../../layui/css/layui.css" media="all">
		<style>
			body {
            margin: 10px;
        }

        .layui-table-tool-temp {
			padding-right: 0;
			margin-right: 0;
			/*text-align: right;*/
		}

		.yutons,
		.layui-btn-sm {
			margin-top: -2px;
		}

		/* 修改头部工具右侧筛选、导出、打印样式 */
		.yutons-header-tool {
			margin-top: -2px;
			width: 30px !important;
			height: 30px !important;
			background-color: #ffffff;
		}

		/* 修改右侧筛选、导出、打印出发的ul标签定位 */
		.layui-table-tool-panel {
			left: auto;
			right: -1px;
		}

		/* div 右侧10px */
		.yutons-btn-margin-right {
			margin-right: 10px;
			line-height: 40px;
		}
    </style>
	</head>
	<body onload="initTextareaNumFun();">
  <div class="layui-form-item">

    <div class="layui-form-item">
      <label class="layui-form-label">Excle名称</label>
      <div class="layui-input-block">
        <input type="text" id="title" required  lay-verify="required" placeholder="请输入标题，默认：河马数据" autocomplete="on" class="layui-input" style="width: 300px;" maxlength="80">
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">行数</label>
      <div class="layui-input-inline" style="width: 100px;">
        <input type="number" id="row" placeholder="行数" autocomplete="on" class="layui-input" value="1">
      </div>
      <div class="layui-form-mid"></div>
      <div class="layui-input-inline" style="width: 100px;">
        <button class="layui-btn" onclick="initTextareaNumFun();" >初始化行数</button>
      </div>
    </div>

    <div class="layui-inline">
      <label class="layui-form-label"></label>
      <div class="layui-input-inline" style="width: 100px;">
        <button class="layui-btn" onclick="exportFile()">导出</button>

      </div>
    </div>
  </div>
		<div id="jsonDataDiv">
			<textarea class="jsonData" id='jsonStr1' style="width: 90%;height: 200px;">
				{"statu":0,"data":[{"executionId":null,"sql":"SELECT ID, mobile, template_code\n\t, CASE template_code\n\t\tWHEN 'SMS_REGISTER_CAPTCHA_CODE' THEN '注册验证码'\n\t\tWHEN 'FORGET_PASSWORD_BUSINESS' THEN '忘记密码验证码'\n\t\tWHEN 'EMAIL_APPLICATIONPASS_TEMPLATE_CODE' THEN '退货单审批通过'\n\t\tWHEN 'EMAIL_REGISTER_TEMPLATE_CODE' THEN '注册成功'\n\t\tWHEN 'MK_FAST_CHECKOUT_CODE' THEN '快速结算验证码'\n\t\tWHEN 'SMS_REGISTER_CAPTCHA_CODE' THEN '注册验证码'\n\t\tWHEN 'EMAIL_NOTICE_TEMPLATE_CODE' THEN '到货通知'\n\t\tWHEN 'MK_MINI_PROGRAM_BIND_MOBILE_CODE' THEN '小程序个人中心绑定手机号标识'\n\t\tWHEN 'EMAIL_ORDERDELIVERIED_TEMPLATE_CODE' THEN '订单发货'\n\t\tWHEN 'EMAIL_APPLICATIONFINISH_TEMPLATE_CODE' THEN '退货申请已通过'\n\t\tELSE 'unknown'\n\tEND AS 短信来源, send_time\n\t, CASE \n\t\tWHEN result_code LIKE 'yiTong|%' THEN 'webPower'\n\t\tELSE '移通'\n\tEND AS 短信供应商, result_code\nFROM t_sys_smssendlog\nWHERE send_time BETWEEN to_date('2023-05-15 09:00:00', 'yyyy-mm-dd HH24:MI:SS') AND to_date('2023-05-23 00:00:00', 'yyyy-mm-dd HH24:MI:SS')\nORDER BY ID DESC\nLIMIT 10","sshTime":0,"connTime":6,"exeTime":16,"buildTime":223,"dataConstructionTime":0,"isTicket":null,"msg":null,"all":null,"dataNumber":10,"valueHeadTime":0,"data":[["ID","mobile","template_code","短信来源","send_time","短信供应商","result_code"],["989519","15637361125","SMS_REGISTER_CAPTCHA_CODE","注册验证码","2023-05-22 23:59:54.874","webPower","yiTong|status:OK|msgId:42500"],["989518","13877020020","EMAIL_REGISTER_TEMPLATE_CODE","注册成功","2023-05-22 23:58:15.318","webPower","yiTong|status:OK|msgId:42499"],["989517","13810582240","SMS_REGISTER_CAPTCHA_CODE","注册验证码","2023-05-22 23:56:14.084","webPower","yiTong|status:OK|msgId:42498"],["989516","18948825727","EMAIL_REGISTER_TEMPLATE_CODE","注册成功","2023-05-22 23:53:02.289","webPower","yiTong|status:OK|msgId:42497"],["989515","15061888291","EMAIL_REGISTER_TEMPLATE_CODE","注册成功","2023-05-22 23:48:14.054","webPower","yiTong|status:OK|msgId:42496"],["989514","18666093314","EMAIL_REGISTER_TEMPLATE_CODE","注册成功","2023-05-22 23:48:12.579","webPower","yiTong|status:OK|msgId:42495"],["989513","15273155414","EMAIL_REGISTER_TEMPLATE_CODE","注册成功","2023-05-22 23:46:40.689","webPower","yiTong|status:OK|msgId:42494"],["989512","15273155414","SMS_REGISTER_CAPTCHA_CODE","注册验证码","2023-05-22 23:44:48.889","webPower","yiTong|status:OK|msgId:42493"],["989511","13901060525","EMAIL_REGISTER_TEMPLATE_CODE","注册成功","2023-05-22 23:42:56.196","webPower","yiTong|status:OK|msgId:42492"],["989510","18856200916","EMAIL_REGISTER_TEMPLATE_CODE","注册成功","2023-05-22 23:41:30.54","webPower","yiTong|status:OK|msgId:42491"]],"columnTypeList":[-5,12,12,12,93,12,12]}],"msg":""}
			</textarea>
		</div>


</script>
		<script src="../../layui/layui.js"></script>
		<script>
			layui.config({
					base: '../../layui_exts/'
				}).use(['table', 'excel'], function() {

			});

			function initTextareaNumFun() {
        $ = layui.$;
				var row = $("#row").val();
				if (row == "") {
					row = 1;
				}
				var jsonDataDiv = $("#jsonDataDiv");
				jsonDataDiv.html("");
				for (var index = 1; index <= row; index++) {
					// <div>河马数据2</div>
					var tempContent = "<div>河马数据";
					tempContent += index;
					tempContent += "</div>";
					tempContent += "<textarea class=\"jsonData\" style=\"width: 90%;height: 200px;\"></textarea>";
					tempContent += "<br/>";
					jsonDataDiv.append(tempContent);
				}
			}

      function exportFile() {
        $ = layui.$;
        var title = $("#title").val();
        if (title == "") {
          title = "河马数据";
        }
        // var dataObj = eval("(" + val + ")");
        // var arrayData = dataObj.data[0].data;

        var array = new Array();
        $("textarea.jsonData").each(function () {
          //循环需要执行的代码
          var val = this.value;
          var size = val.length;
          if (size > 0) {
            var dataObj = eval("(" + val + ")");
            var arrayData = dataObj.data[0].data;

            if (array.length === 0) {
              array = arrayData;
            } else {
              var len = arrayData.length;
              if (len >= 2) {
                arrayData.shift();
                for(var index=0; index<=len-2; index++){
                  array.push(arrayData[index]);
                }
              }
            }
          }
        });
        if (array.length == 0) {
          alert("请输入河马数据");
          return;
        }

        //导出excel
        excel = layui.excel;
        excel.exportExcel({
          sheet1: array
        }, title +"_"+ new Date().toLocaleString() + '.xlsx', 'xlsx');
      }
		</script>
	</body>
</html>
